<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\Request;

class SDKNameNotFoundException extends Exception
{
    protected $code = 500;
    protected $message = 'SDK_NAME not exist';

    public function __construct()
    {
        parent::__construct($this->message, $this->code);
    }

    public function render(Request $request)
    {
        if ($request->expectsJson()) {
            // json() 方法第二个参数就是 Http 返回码
            return response()->json(['msg' => $this->message, 'code' => $this->code, 'data' => null], $this->code);
        }
        // 有些地方可能不按标准的json请求头 ，所以这里也强制返回json
        return response()->json(['msg' => $this->message, 'code' => $this->code, 'data' => null], $this->code);
    }
}
